<template>
    <div class="page_subsidy">
        <common-header :title="'补贴编辑'" :showBack="true"></common-header>
        <div class="btn-save" @click="saveInfo">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info item-subsidy">
                <div class="item-item every-block-padding item-type" style="padding: 0 0 0 0.4rem !important;">
                    <span class="item-itemLabel" v-model="typename">补贴类型</span>
                    <div class="translateBlock" style="width: 7.1rem;text-align: right;"
                         @click="chooseItem">{{typename}}
                    </div>
                    <div class="translateBlock" style="width: 0.5rem;text-align: center;vertical-align: middle;"
                         @click="chooseItem">
                        <img src="../../../static/images/img-left.png" style="width: 18px;"/>
                    </div>
                </div>
                <group>
                    <x-switch title="是否参保/享受" v-model="hadjoin"></x-switch>
                </group>
                <div class="item-item">
                    <x-input title="补助金额（元）" type="number" v-model="amount"
                             placeholder="请输入补助金额（元）">
                    </x-input>
                </div>
                <group>
                    <x-switch title="是否发放" v-model="sendstatus"></x-switch>
                </group>
                <div v-show="sendstatus">
                    <div class="item-item">
                        <datetime :min-year="1900" title="发送时间" placeholder="请选择发放时间" v-model="sendtime1"></datetime>
                    </div>
                    <div class="item-item">
                        <x-input title="发放账户" v-model="receiveaccount"
                                 placeholder="发放账户">
                        </x-input>
                    </div>
                </div>
                <div class="item-item">
                    <x-input title="发放标准（元）" type="number" v-model="criterion"
                             placeholder="请输入发放标准">
                    </x-input>
                </div>
            </div>
            <group title="备注">
                <x-textarea :max="20" v-model="remarks" placeholder="请输入备注"></x-textarea>
            </group>

        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'
    import {XSwitch, Group, Cell, XInput, Datetime, XTextarea} from 'vux'

    export default {
        name: "subsidy",
        components: {
            XSwitch,
            Group,
            Cell,
            XInput,
            Datetime,
            XTextarea
        },
        data() {
            return {
                itemId: this.$route.query.itemId,
                familyid: this.$route.query.familyid,
                typeid: this.$route.query.typeid,
                typename: this.$route.query.typename,
                id: this.$route.query.id,
                hadjoin: Number(this.$route.query.hadjoin) ? true : false,
                amount: this.$route.query.amount ? this.$route.query.amount : '',
                sendstatus: Number(this.$route.query.sendstatus) ? true : false,
                sendtime1: this.$route.query.sendtime ? this.$route.query.sendtime : '',
                receiveaccount: this.$route.query.receiveaccount ? this.$route.query.receiveaccount : '',
                criterion: this.$route.query.criterion ? this.$route.query.criterion : '',
                remarks: this.$route.query.remarks ? this.$route.query.remarks : '',
            }
        },

        created() {

        },
        watch: {},
        methods: {
            // 保存纠纷记录
            saveInfo() {
                if (!this.typename) {
                    this.$vux.toast.show({
                        text: '请选择补贴类型',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                }
                if (!this.amount) {
                    this.$vux.toast.show({
                        text: '请输入补助金额',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                }

                let param = {
                    receiveperson: this.id,
                    familyid: this.familyid,
                    typeid: this.typeid,
                    typename: this.typename,
                    hadjoin: this.hadjoin ? 1 : 0,
                    amount: this.amount,
                    sendstatus: this.sendstatus ? 1 : 0,
                    sendtime: this.sendtime1 ? this.sendtime1 + ' ' + '00:00:00' : '',
                    receiveaccount: this.receiveaccount,
                    criterion: this.criterion,
                    remarks: this.remarks,
                }

                if (this.itemId) {
                    param = Object.assign(param, {id: this.itemId})
                    let _param = this.$tools.invokeUAF('subsidyinfo/editSubsidyinfo', param)
                    resident.editSubsidyinfo(_param).then(res => {
                        let data = res.data.data;
                    })
                } else {
                    let _param = this.$tools.invokeUAF('subsidyinfo/addSubsidyinfo', param)
                    resident.addSubsidyinfo(_param).then(res => {
                        let data = res.data.data;
                    })
                }

            },
            chooseItem() {
                this.$tools.goPage_query('subsidytype', {
                    itemId: this.itemId,
                    familyid: this.familyid,
                    receiveperson: this.id,
                    typeid: this.typeid,
                    typename: this.typename,
                    hadjoin: this.hadjoin ? 1 : 0,
                    amount: this.amount,
                    sendstatus: this.sendstatus ? 1 : 0,
                    sendtime: this.sendtime,
                    receiveaccount: this.receiveaccount,
                    criterion: this.criterion,
                    remarks: this.remarks,
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/less">
    .page_subsidy {
        .item-info {
            .weui-cells {
                margin-top: 0 !important;
            }
        }

        .item-subsidy {
            .vux-x-switch {
                padding-top: 5px !important;
                padding-bottom: 5px !important;
            }
        }
    }
</style>
